package model;


import java.util.Collections;

import controller.Main;




public class ABook extends Contact {

private String Name;


public ABook(String Name){
	super();
	this.Name=Name;
	}
/*
public void printList(){
	try{
	    BufferedReader buf1=new BufferedReader(new FileReader("Abook.txt"));
	    try {
	    	String line;
	    	while ((line = buf1.readLine()) != null) {
	    		String[] word= null;
	    		for(int i=1; i<= 10; i++){
	    			word = line.split(" ");
	    		}
	    			Contact c= new Contact(word[1],word[2],word[3],word[4],word[5],word[6],word[7],word[8]);
	    			tab.add(c);
	    		
	    	}
	    } finally {
	    	buf1.close();
	    }
	    } catch (IOException ioe) {
	    
		System.out.println("Error" + ioe.toString());
		}
}
*/

public String getName() {
	return Name;
}


public void setName(String name) {
	Name = name;
}

/**
 * Add a new Contact
 */
public static void add(Contact c){
	Main.tab.add(c);
		/*
	try{
	FileWriter fw = new FileWriter ("Abook.txt",true) ; 
	BufferedWriter bw = new BufferedWriter (fw) ; 
	bw.newLine(); 
	PrintWriter pw = new PrintWriter (bw) ; 
	pw. print (Main.tab) ; 
	pw. close () ; 
	}catch(IOException e){
		System.out.println("Error");
	}
	*/
}

/**
 * Remove a contact
 */
public void remove(Contact c){
	Main.tab.remove(c);
}
/**
 * Modify a Contact
 */
public void modify(Contact c){
	c.setFirstName(c.firstName);
	c.setLastName(c.lastName);
	c.setHomeAddress(c.homeAddress);
	c.setCompanyAddress(c.companyAddress);
	c.setPersonalPhone(c.personalPhone);
	c.setHomePage(c.homePage);
	c.setEmail(c.email);
	c.setPhoto(c.photo);
	c.setGroup(c.group);
}


/**
 * Display contact's details
 */
public void display(Contact c){
	String res="";
	for (Contact l:Main.tab){
		if(l.getFirstName() == c.getFirstName()) res=res+ "Details: " +l.toString();
}
	}

/**
 * Set contact per alphabetical order
 */
public void alphabetical (Contact c){
	Collections.sort(Main.tab,null);
		
} 


@Override
public String toString() {
	String res="";
	for (Contact l: Main.tab){
		res=res+ "\nContact: " +l.toString();
		}
	return res;
}	


	
}
